#include "../DataStructures/binary_tree.h"

typedef struct _subs {
    int key;
    char name[20];
} subs;

int t_key_cmp(const void *a, const void *b) {
    if (((subs *) a)->key > ((subs *) b)->key) return 1;
    else if (((subs *) a)->key < ((subs *) b)->key) return -1;

    return 0;
}

void t_data_copy(void *dest, const void *src) {
    subs *n = dest;
    ((subs *) n)->key = ((subs *) src)->key;
    strcpy(((subs *) n)->name, ((subs *) src)->name);
}

void t_del_node(void *n) {
    LOG(LOG_DBG, "deleting [%d:%s]", ((subs *) n)->key, ((subs *) n)->name);
    return;
}

void t_print_node(const void *n) {
    LOG(LOG_INFO, "[%d:%s]", ((subs *) n)->key, ((subs *) n)->name);
    return;
}

int bst_driver() {
    int k, cases, res;
    BST bst;
    subs s;

#ifndef ONLINE_JUDGE
    freopen("bst.in", "r", stdin);
#endif

    bst_init(&bst, sizeof (subs), t_key_cmp, t_data_copy, t_del_node, t_print_node);

    scanf("%d", &cases);
    while (cases--) {
        scanf("%d", &k);
        while (k--) {
            scanf("%d%s", &s.key, s.name);
            res = bst_insert(&bst, &s);
        }

        bst_inorder(&bst);

        s.key = 3;
        printf("Deleting node with key [%d]\n", s.key);
        bst_delete(&bst, &s);
        bst_inorder(&bst);
        
        bst_clean(&bst);
    }

    return 0;
}